package www.cslc.com.RMI.service;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class RmiUtil {
	private static RmiUtil instance;
	private IExecuteErrorTaskService executeErrorTaskRmiClient;
	@SuppressWarnings("resource")
	private RmiUtil (){
		String path = System.getProperty("user.dir");  
		ApplicationContext ctx =new FileSystemXmlApplicationContext(path + "\\conf\\applicationContext-ExecuteErrorTaskRmiClient.xml");  
		executeErrorTaskRmiClient = (IExecuteErrorTaskService) ctx.getBean("executeErrorTaskRmiClient");
	}
	public static  RmiUtil getInstance() {
		if (instance == null) {
			synchronized(RmiUtil.class){
				if (instance == null)
				instance = new RmiUtil();
			}
		}
		return instance;
	}
	
	public boolean runTask(String gameNo,String drawNo,String taskName,String businessDate) throws Exception{
		boolean rs = false;
			rs = executeErrorTaskRmiClient.executeErrorTask(gameNo, drawNo, taskName, businessDate);
		return rs;
	}
	
	public boolean executeInstantAgentProvinceCheckTask(String gameNo, String businessDate){
		boolean rs = false;
		try{
			rs = executeErrorTaskRmiClient.executeInstantAgentProvinceCheckTask(gameNo, businessDate);
		} catch(Exception e){
			e.printStackTrace();		
		}
		return rs;
	}
	public boolean executeInstantProvinceGameCheckTask(String businessDate, List<String> gameNoLt){
		boolean rs = false;
		try{
			rs = executeErrorTaskRmiClient.executeInstantProvinceGameCheckTask(businessDate, gameNoLt);
		} catch(Exception e){
			e.printStackTrace();		
		}
		return rs;
	}
	public boolean executeInstantWinTicketTask(String businessDate, List<String> gameNoLt){
		boolean rs = false;
		try{
			rs = executeErrorTaskRmiClient.executeInstantWinTicketTask(businessDate, gameNoLt);
		} catch(Exception e){
			e.printStackTrace();		
		}
		return rs;
	}
	public boolean executeInstantRdcPayTicketTask(String businessDate){
		boolean rs = false;
		try{
			rs = executeErrorTaskRmiClient.executeInstantRdcPayTicketTask(businessDate);
		} catch(Exception e){
			e.printStackTrace();		
		}
		return rs;
	}
	
	public IExecuteErrorTaskService getExecuteErrorTaskRmiClient() {
		return executeErrorTaskRmiClient;
	}

	public void setExecuteErrorTaskRmiClient(
			IExecuteErrorTaskService executeErrorTaskRmiClient) {
		this.executeErrorTaskRmiClient = executeErrorTaskRmiClient;
	}
	
	public static void main(String[] args) {
		RmiUtil.getInstance();
	}
}
